package com.seehope.practice;

public class CrossPrint {

	public static void main(String[] args) {
		final MyPrinter p = new MyPrinter();
		new Thread() {
			public void run() {
				try {
					p.printChar();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		}.start();
		new Thread() {
			public void run() {
				try {
					p.printNum();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		}.start();
	}
}
class MyPrinter {
	public void printChar() throws InterruptedException {
		for (int i = 65; i < 91; i++) {
			synchronized (this) {
				System.out.print((char) i);
				try {
					Thread.sleep(1000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				this.notify();
				try {
					this.wait();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		}
	}
	public void printNum() throws InterruptedException {
		for (int i = 1; i <= 26; i++) {
			synchronized (this) {
				System.out.print(i);
				try {
					Thread.sleep(1000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				this.notify();
				try {
					this.wait();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		}
	}
}

